'use strict'
const _ = require('lodash')
const { Controller } = require('ee-core')
const Log = require('ee-core/log')
const Services = require('ee-core/services')
const {
    app: electronApp, dialog, shell, Notification,
    powerMonitor, screen, nativeTheme
} = require('electron')/**
 * example
 * @class
 */
class ExampleController extends Controller {

    constructor(ctx) {
        super(ctx)
    }


    /**
     * 所有方法接收两个参数
     * @param args 前端传的参数
     * @param event - ipc通信时才有值。详情见：控制器文档
     */

    /**
     * fsSearch
     */
    async fsSearch (args) {
        const result = await Services.get('fs').fsSearch(args)
        return result
    }
    async fsReplace (args) {
        const result = await Services.get('fs').fsReplace(args)
        return result
    }
    async getGitFiles (args) {
        const result = await Services.get('gitSearch').getFile(args)
        return result
    }
    async getGitUsername (args) {
        const result = await Services.get('gitSearch').getGitUserName(args)
        return result
    }
    // async dayReport (args) {
    //     await Services.get('playwrightService').startWork()
    // }
    openDirectory (args) {
        if (!args.path) {
            return false
        }
        shell.openPath(args.path)
        return true
    }
    /**
   * 选择目录
   */
    selectFolder () {
        const filePaths = dialog.showOpenDialogSync({
            properties: ['openDirectory', 'createDirectory']
        })

        if (_.isEmpty(filePaths)) {
            return null
        }

        return filePaths[0]
    }
    /**
   * 脱敏
   */
    async desensitization (args) {
        const result = await Services.get('desensitizationService').desensitization(args)
        return result
    }
    async readFile (args) {
        const result = await Services.get('desensitizationService').readFile(args)
        return result
    }
}

ExampleController.toString = () => '[class ExampleController]'
module.exports = ExampleController  